package main

import (
	"fmt"
	"os"
	"time"
)

func DoPanic(cnt int) {
	//panic("panic 1")
	if cnt == 5 {
		panic("panic 5")
	}
	fmt.Println("hellow")
	time.Sleep(time.Duration(2) * time.Second)
}

func RedirectPanic(path string) bool {
	f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		fmt.Println(err)
		return false
	}
	os.Stdout = f
	os.Stderr = f
	return true
}

func main() {
	RedirectPanic("./log.txt")
	cnt := 0
	for {
		DoPanic(cnt)
		cnt++
	}
}